package com.ccx.coachsite.bus;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;

import com.ccx.coachsite.util.Log;
import com.ccx.coachsite.util.SharedPreferencesUtil;

public class ExpertExInfo {
	private String node;
	private String levelName;
	private String placeName;
	private String notices;
	private int claimNums;
	private int claimedNums;
	private ArrayList<levelInfo> levelList;
	
	public static ExpertExInfo getExpertExInfo(Context context)
	{
		String countStr = SharedPreferencesUtil.getValue(context,
				SharedKey.Custom_ExpertEx_Info, "");
		
		try {
			JSONObject jsonObject = new JSONObject(countStr);
			
			if(jsonObject.isNull("response"))
				return null;
			
			ExpertExInfo einfo = new ExpertExInfo();
			JSONObject respsonObject = jsonObject.getJSONObject("response");
			einfo.setNode(respsonObject.optString("node"));
			einfo.setLevelName(respsonObject.optString("levelName"));
			einfo.setPlaceName(respsonObject.optString("placeName"));
			einfo.setNotices(respsonObject.optString("notices"));
			einfo.setClaimNums(respsonObject.optInt("claimNums"));
			einfo.setClaimedNums(respsonObject.optInt("claimedNums"));
			
			JSONArray array = respsonObject.optJSONArray("levelList");
			if(array != null)
			{
				ArrayList<levelInfo> lst = new ArrayList<levelInfo>();
				einfo.setLevelList(lst);
				for (int i = 0; i < array.length(); i++) {
					JSONObject jsonObj = array.getJSONObject(i);
					levelInfo linfo = new levelInfo();
					linfo.setLevelName(jsonObj.optString("levelName"));
					linfo.setLevelNum(jsonObj.optInt("claimNums"));
					lst.add(linfo);
				}
			}
			
			return einfo;
		} catch (Exception e) {
			Log.e(e.getMessage(), e);
		} finally {
		}
		
		return null;
	}
	
	public int getLevelCount()
	{
		if(levelList != null)
			return levelList.size();
		
		return 0;
	}
	
	public int getMaxLevelNum()
	{
		if(levelList != null && levelList.size() > 0)
		{
			levelInfo linfo = levelList.get(levelList.size() -1);
			return linfo.getLevelNum();
		}
		
		return 0;
	}
	
	public String getNode() {
		return node;
	}
	public void setNode(String node) {
		this.node = node;
	}
	public String getLevelName() {
		return levelName;
	}
	public void setLevelName(String levelName) {
		this.levelName = levelName;
	}
	public String getPlaceName() {
		return placeName;
	}
	public void setPlaceName(String placeName) {
		this.placeName = placeName;
	}
	public String getNotices() {
		return notices;
	}
	public void setNotices(String notices) {
		this.notices = notices;
	}
	public int getClaimNums() {
		return claimNums;
	}
	public void setClaimNums(int claimNums) {
		this.claimNums = claimNums;
	}
	public int getClaimedNums() {
		return claimedNums;
	}
	public void setClaimedNums(int claimedNums) {
		this.claimedNums = claimedNums;
	}
	public ArrayList<levelInfo> getLevelList() {
		return levelList;
	}
	public void setLevelList(ArrayList<levelInfo> levelList) {
		this.levelList = levelList;
	}
}
